package com.example.battle.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.battle.R;
import com.example.battle.activity.FansNameDetailActivity;
import com.example.battle.db.BattleDao;
import com.example.battle.entity.FansName;

import java.util.List;

public class SearchFansItemAdapter extends RecyclerView.Adapter<SearchFansItemAdapter.MyViewHolder> {
    private List<FansName> mDataItemList;
    private BattleDao battleDao;
    public SearchFansItemAdapter(List<FansName> dataItemList){
        this.mDataItemList = dataItemList;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        public TextView textView1,textView2;
        public MyViewHolder(View v){
            super(v);
            textView1 = v.findViewById(R.id.search_item_fansname);
            textView2 = v.findViewById(R.id.search_item_starname);
        }
    }

    @Override
    public SearchFansItemAdapter.MyViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
//        创建视图
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_fans_item,parent,false);
        final MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
//        绑定数据
        FansName dataItem = mDataItemList.get(position);
        holder.textView1.setText(dataItem.getFansName());
        holder.textView2.setText(dataItem.getStarName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                FansName dataItem = mDataItemList.get(position);
                Intent intent = new Intent(v.getContext(), FansNameDetailActivity.class);
                intent.putExtra("fansName",dataItem);
                v.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataItemList.size();
    }
}
